/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package convert;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.inject.Named;
import model.entity.Task;
import service.ITaskmanager;
import service.InterfaceServiceLocal;

/**
 *
 * @author dingnangen
 */
@Named("taskConvert")
@RequestScoped
public class TaskConvert implements Converter {

    @EJB(beanName = "TaskManager")
    private ITaskmanager taskManager;

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        System.out.println("getAsObject component:"+component.getClass()+"#"+value);
        return taskManager.find(Integer.parseInt(value));

    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        System.out.println("getAsString component:"+component.getClass()+"#"+((Task) value).getIdtask().toString());
        return ((Task) value).getIdtask().toString();

    }

}
